// event-bus.js
const eventBus = {
  events: {},
  emit(event, ...args) {
    const handlers = this.events[event];
    if (handlers) {
      handlers.forEach((handler) => handler(...args));
    }
  },
  on(event, handler) {
    if (!this.events[event]) {
      this.events[event] = [];
    }
    this.events[event].push(handler);
  },
  off(event, handler) {
    const handlers = this.events[event];
    if (handlers) {
      const index = handlers.indexOf(handler);
      if (index !== -1) {
        handlers.splice(index, 1);
      }
    }
  },
};

export default eventBus;
